﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;

namespace MemoBoss
{
    public class ScoreHelper
    {
        public static int GetHighScore(DifficultyLevel diff)
        {
            string settingName = string.Format("HighScore_{0}", diff.ToString());
            int score = 0;
            lock (App.settingsOperationLock)
            {
                if (IsolatedStorageSettings.ApplicationSettings.Contains(settingName))
                {
                    score = (int)IsolatedStorageSettings.ApplicationSettings[settingName];
                }
            }
            return score;
        }
        public static int GetHighScore(int mode)
        {
            DifficultyLevel diff = 0;
            switch (mode)
            {
                case 0:
                    diff = DifficultyLevel.Easy;
                    break;
                case 1:
                    diff = DifficultyLevel.Hard;
                    break;
                case 2:
                    diff = DifficultyLevel.Medium;
                    break;
                case 3:
                    diff = DifficultyLevel.MemoBoss;
                    break;
            }
            string settingName = string.Format("HighScore_{0}", diff.ToString());
            int score = 0;
            lock (App.settingsOperationLock)
            {
                if (IsolatedStorageSettings.ApplicationSettings.Contains(settingName))
                {
                    score = (int)IsolatedStorageSettings.ApplicationSettings[settingName];
                }
            }
            return score;
        }

        public static void SaveHighScore(int mode, int score)
        {
            DifficultyLevel diff = 0;
            switch (mode)
            {
                case 0:
                    diff = DifficultyLevel.Easy;
                    break;
                case 1:
                    diff = DifficultyLevel.Hard;
                    break;
                case 2:
                    diff = DifficultyLevel.Medium;
                    break;
                case 3:
                    diff = DifficultyLevel.MemoBoss;
                    break;
            }
            string settingName = string.Format("HighScore_{0}", diff.ToString());

            lock (App.settingsOperationLock)
            {
                if (IsolatedStorageSettings.ApplicationSettings.Contains(settingName))
                {
                    var points = (int)IsolatedStorageSettings.ApplicationSettings[settingName];
                    if (points < score)
                    {
                        IsolatedStorageSettings.ApplicationSettings[settingName] = score;
                    }
                }
                else
                {
                    IsolatedStorageSettings.ApplicationSettings.Add(settingName, score);

                }
                IsolatedStorageSettings.ApplicationSettings.Save();

            }

        }
        public static void SaveHighScore(DifficultyLevel diff, int score)
        {
            string settingName = string.Format("HighScore_{0}", diff.ToString());

            lock (App.settingsOperationLock)
            {
                if (IsolatedStorageSettings.ApplicationSettings.Contains(settingName))
                {
                    var points = (int)IsolatedStorageSettings.ApplicationSettings[settingName];
                    if (points < score)
                    {
                        IsolatedStorageSettings.ApplicationSettings[settingName] = score;
                    }
                }
                else
                {
                    IsolatedStorageSettings.ApplicationSettings.Add(settingName, score);

                }
                IsolatedStorageSettings.ApplicationSettings.Save();

            }

        }
    }
}
